﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using System.Diagnostics;

namespace TextToSpeechEngine
{
    class WordRepresentationDatabase
    {

        List<WordRepresentation> wordRepresentations;

        public WordRepresentationDatabase()
        {
            wordRepresentations = new List<WordRepresentation>();
        }

        public List<WordRepresentation> WordRepresentations
        {
            get
            {
                List<WordRepresentation> wordRepresentationsCopy = new List<WordRepresentation>();

                foreach (WordRepresentation wordRepresentation in wordRepresentations)
                {
                    wordRepresentationsCopy.Add(wordRepresentation);
                }

                return wordRepresentationsCopy;
            }
            set
            {

                wordRepresentations.Clear();

                foreach (WordRepresentation wordRepresentation in value)
                {
                    wordRepresentations.Add(wordRepresentation);
                }
            }
        }

        //file format is
        //string int[]
        //Word PhonemeIDList
        //Cat 23 1 44 
        public void LoadFromFile(string fileName)
        {
            string[] lines = File.ReadAllLines(fileName);
            foreach (string line in lines)
            {
                if (line.Length > 0)
                {
                    string[] entries = line.Split(' ');
                    string word = entries[0];
                    WordRepresentation newRepresentation = new WordRepresentation();
                    newRepresentation.Word = word;

                    List<int> phonemeIDs = new List<int>();
                    for (int iEntryNr = 1; iEntryNr < entries.Length; iEntryNr++)
                    {
                        phonemeIDs.Add(Convert.ToInt32(entries[iEntryNr]));
                    }
                    newRepresentation.PhonemeIDs = phonemeIDs;

                    wordRepresentations.Add(newRepresentation);
                }
            }
        }
    }
}